#ifndef _BUOLA_MEDIA_CODEC_BFFMPEGDECODER_H_
#define _BUOLA_MEDIA_CODEC_BFFMPEGDECODER_H_

#include <buola/bbox/bservice.h>

#include <buola/bbox/bstreamin.h>
#include <buola/bbox/bstreamout.h>
#include <buola/bbox/bdataout.h>

#include <buola/image/format.h>

namespace buola { namespace media {

namespace ffmpeg {

    class CInputContext;
    class CInputAudioStream;
    class CInputVideoStream;
    
/*namespace ffmpeg*/ }
    
class BFfmpegDecoder : public bbox::BService<BFfmpegDecoder>
{
    struct SAudio
    {
        bbox::BStreamOut<int16_t> *oAudio;
        
        std::unique_ptr<ffmpeg::CInputAudioStream> mStream;
    };
    
    struct SVideo
    {
        bbox::BDataOut<img::CImage_rgb8> *oVideo;
        
        std::unique_ptr<ffmpeg::CInputVideoStream> mStream;
    };

public:
    BFfmpegDecoder();
    ~BFfmpegDecoder();

    void Loop();

private:
    virtual void DoInitialize();
    virtual void DoActivate();

private:
    std::unique_ptr<ffmpeg::CInputContext> mCtx;
    std::vector<std::unique_ptr<SAudio>> mAudio;
    std::vector<std::unique_ptr<SVideo>> mVideo;

public:
    bbox::BStreamIn<uint8_t> iData;
    std::vector<bbox::BStreamOut<int16_t>*> oAudio;
    std::vector<bbox::BDataOut<img::CImage_rgb8>*> oVideo;
};

/*namespace media*/ } /*namespace buola*/ }

#endif
